{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ac4b1599",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from keras.layers import Input, Dense, Dropout, Activation,Conv2D,MaxPool2D,Flatten\n",
    "from keras.datasets import mnist\n",
    "from keras.models import Model\n",
    "from keras.utils import to_categorical\n",
    "from keras.callbacks import TensorBoard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28f8fafc",
   "metadata": {},
   "outputs": [],
   "source": [
    "log_dir='./logs',  # 默认保存在当前文件夹下的logs文件夹之下\n",
    "histogram_freq=0,\n",
    "batch_size=32,\n",
    "write_graph=True,  #默认是True，默认是显示graph的。\n",
    "write_grads=False,\n",
    "write_images=False,\n",
    "update_freq='epoch'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e3329c34",
   "metadata": {},
   "outputs": [],
   "source": [
    "Tensorboard= TensorBoard??"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6cc5f125",
   "metadata": {},
   "outputs": [],
   "source": [
    "TensorBoard??"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "eec25b40",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[33mWARNING: Package(s) not found: transformers\u001b[0m\u001b[33m\r\n",
      "\u001b[0m"
     ]
    }
   ],
   "source": [
    "!pip show transformers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "035b6ad9",
   "metadata": {},
   "outputs": [],
   "source": [
    "open??"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff92fa05",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18aa40e5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5b99cc65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:`write_grads` will be ignored in TensorFlow 2.0 for the `TensorBoard` Callback.\n",
      "Epoch 1/2\n",
      "375/375 [==============================] - 32s 84ms/step - loss: 0.5582 - acc: 0.9086 - val_loss: 0.0612 - val_acc: 0.9825\n",
      "Epoch 2/2\n",
      "375/375 [==============================] - 33s 88ms/step - loss: 0.0996 - acc: 0.9714 - val_loss: 0.0534 - val_acc: 0.9847\n"
     ]
    }
   ],
   "source": [
    "\n",
    "(x_train,y_train),(x_test,y_test) = mnist.load_data()\n",
    "x_train=np.expand_dims(x_train,axis=-1)\n",
    "x_test=np.expand_dims(x_test,axis=-1)\n",
    "y_train=to_categorical(y_train,num_classes=10)\n",
    "y_test=to_categorical(y_test,num_classes=10)\n",
    "batch_size=128\n",
    "epochs=2\n",
    "inputs = Input([28,28,1])\n",
    "x = Conv2D(32, (5,5), activation='relu')(inputs)\n",
    "x = Conv2D(64, (5,5), activation='relu')(x)   \n",
    "x = MaxPool2D(pool_size=(2,2))(x)\n",
    "x = Flatten()(x)    \n",
    "x = Dense(128, activation='relu')(x)\n",
    "x = Dropout(0.5)(x)\n",
    "x = Dense(10, activation='softmax')(x)\n",
    "model = Model(inputs,x)\n",
    "model.compile(loss='categorical_crossentropy', optimizer=\"adam\",metrics=['acc']) \n",
    "Tensorboard= TensorBoard(log_dir=\"./model\", \n",
    "                         histogram_freq=1,\n",
    "                         write_grads=True,\n",
    "                         write_images=True)\n",
    "history=model.fit(x_train, \n",
    "                  y_train,\n",
    "                  batch_size=batch_size, \n",
    "                  epochs=epochs, \n",
    "                  shuffle=True, \n",
    "                  validation_split=0.2,\n",
    "                  callbacks=[Tensorboard])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c31f208b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2fa9d692",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(188.10524374999994, 36)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 10\n",
    "up = 0.15\n",
    "\n",
    "t = 60\n",
    "\n",
    "for i in range(5):\n",
    "    t = t * (1 + up) + a\n",
    "\n",
    "t, 2*18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e5035118",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "67"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "37 + 24 + 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "abdf676c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[11, 12]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def add_(x):\n",
    "    return x+10\n",
    "\n",
    "list(map(add_, [1, 2]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa4b24be",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bc3c341",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab1459ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
